package com.connection.second.wallpaper.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.connection.second.common.annotation.Anonymous;
import com.connection.second.common.constant.Constants;
import com.connection.second.common.constant.UserConstants;
import com.connection.second.common.core.domain.entity.SysUser;
import com.connection.second.common.core.domain.model.LoginBody;
import com.connection.second.common.exception.user.BlackListException;
import com.connection.second.common.exception.user.UserNotExistsException;
import com.connection.second.common.exception.user.UserPasswordNotMatchException;
import com.connection.second.common.utils.MessageUtils;
import com.connection.second.common.utils.SecurityUtils;
import com.connection.second.common.utils.StringUtils;
import com.connection.second.common.utils.ip.IpUtils;
import com.connection.second.framework.manager.AsyncManager;
import com.connection.second.framework.manager.factory.AsyncFactory;
import com.connection.second.wallpaper.domain.dto.UserLoginDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.connection.second.common.annotation.Log;
import com.connection.second.common.core.controller.BaseController;
import com.connection.second.common.core.domain.AjaxResult;
import com.connection.second.common.enums.BusinessType;
import com.connection.second.wallpaper.domain.entity.PaperUserInfo;
import com.connection.second.wallpaper.service.IPaperUserInfoService;
import com.connection.second.common.utils.poi.ExcelUtil;
import com.connection.second.common.core.page.TableDataInfo;

/**
 * 用户管理Controller
 * 
 * @author FL
 * @date 2024-11-15
 */
@RestController
@Api("用户信息管理")
@RequestMapping("/wallpaper")
public class PaperUserInfoController extends BaseController
{
    @Autowired
    private IPaperUserInfoService paperUserInfoService;


    /**
     * 查询用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:list')")
    @GetMapping("/userInfo/list")
    public TableDataInfo list(PaperUserInfo paperUserInfo)
    {
        startPage();
        List<PaperUserInfo> list = paperUserInfoService.selectPaperUserInfoList(paperUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:export')")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/userInfo/export")
    public void export(HttpServletResponse response, PaperUserInfo paperUserInfo)
    {
        List<PaperUserInfo> list = paperUserInfoService.selectPaperUserInfoList(paperUserInfo);
        ExcelUtil<PaperUserInfo> util = new ExcelUtil<PaperUserInfo>(PaperUserInfo.class);
        util.exportExcel(response, list, "用户管理数据");
    }

    /**
     * 获取用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:query')")
    @GetMapping(value = "/userInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        PaperUserInfo userInfo = paperUserInfoService.selectPaperUserInfoById(id);

        return AjaxResult.success(userInfo);
    }

    /**
     * 用户获取个人信息
     */
    @PreAuthorize("@ss.hasRole('user')")
    @GetMapping(value = "/personalInfo")
    public AjaxResult getUserInfo()
    {
        return AjaxResult.success( paperUserInfoService.selectPaperUserInfoByAccountId(getUserId()));
    }

    /**
     * 新增用户管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:add')")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping("/userInfo")
    public AjaxResult add(@RequestBody PaperUserInfo paperUserInfo)
    {
        return toAjax(paperUserInfoService.insertPaperUserInfo(paperUserInfo));
    }

    /**
     * 修改用户管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping ("/userInfo")
    public AjaxResult edit(@RequestBody PaperUserInfo paperUserInfo)
    {
        return toAjax(paperUserInfoService.updatePaperUserInfo(paperUserInfo));
    }

    /**
     * 删除用户管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:userInfo:remove')")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/userInfo/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperUserInfoService.deletePaperUserInfoByIds(ids));
    }
}
